<%--
  Created by IntelliJ IDEA.
  User: Albert Lee
  Date: 2020/5/28
  Time: 18:51
  To change this template use File | Settings | File Templates.
--%>
<%--
  Created by IntelliJ IDEA.
  User: 长风
  Date: 2019/9/21
  Time: 20:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.sql.*" %>
<html>
<head>
    <title>数据更新</title>
</head>
<body>
<%!
    public static final String DBDRIVER = "com.mysql.cj.jdbc.Driver";
    public static final String DBURL = "jdbc:mysql://localhost:3306/student";
    public static final String DBUSER = "root";
    public static final String DBPASS = "123456";
%>
<%
    Connection conn = null;
    PreparedStatement pst = null;
    ResultSet rs = null;
    String id = null;
%>
<%
    try {
        Class.forName(DBDRIVER);
        conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
        request.setCharacterEncoding("utf-8");
        id = request.getParameter("id");
        String sql_update = "select * from stu where id='" + id + "'";
        //获取你要更新数据的id的数据库信息
        pst = conn.prepareStatement(sql_update);
        rs = pst.executeQuery();
        if (rs.next()) {
%>
<form action="doupdate.jsp?id=<%=rs.getString("id")%>" method="post">
    <%--切换到doupdate,显示要更新的数据信息--%>
    名：<input type="text" value="<%=rs.getString("name")%>" name="name">
    性： <input type="text" value="<%=rs.getString("gender") %>" name="gender">
    业： <input type="text" value="<%=rs.getString("major") %>" name="major">

    <input type="submit" value="修改">
</form>
<%
        }
    } catch (Exception e) {
        out.println(e);
    }
%>

</body>
</html>

